﻿//-----------------------------------------------------------------------
// <copyright file="About.cs" company="MAPILab Ltd">
//     Copyright (c) MAPILab Ltd.  All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace MAPILab.SharePoint.Explorer.Information
{
    using System;
    using System.Reflection;
    using System.Windows.Forms;
    using MAPILab.SharePoint.Explorer.Properties;
    using Microsoft.VisualBasic.ApplicationServices;

    /// <summary>
    /// About form
    /// </summary>
    public partial class MLAbout : Form
    {
        #region Field

        /// <summary>
        /// Information for executed assembly
        /// </summary>
        AssemblyInfo info = new AssemblyInfo(Assembly.GetExecutingAssembly());

        #endregion

        #region Constructor

        /// <summary>
        /// Form constructor
        /// </summary>
        public MLAbout()
        {
            InitializeComponent();

            this.Text = String.Format("About {0}", info.Title);
            mlCopyRight.Text = info.Copyright;
            productName1.Text = info.ProductName;
            productVersion.Text = info.Version.ToString();
            releaseDate.Text = Properties.Settings.Default.releaseDate.ToString("D");
        }

        #endregion

        #region Events

        /// <summary>
        /// Copy Info Click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void copyInfo_Click(object sender, EventArgs e)
        {
            CopyInfoToClipboard();
        }

        /// <summary>
        /// Show system Info
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void systemInfo_Click(object sender, EventArgs e)
        {
            try
            {
                System.Diagnostics.Process.Start("MSInfo32.exe");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        /// <summary>
        /// Show help
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void helpButton_Click(object sender, EventArgs e)
        {
            MLHtmlHelper.ShowTopic(this, "explorer", 101);
        }

        /// <summary>
        /// Go to url
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void linkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            string url = (sender as LinkLabel).Text;
            System.Diagnostics.Process.Start(url);
        }

        #endregion

        #region Methods

        /// <summary>
        /// Copy Information to the clipboard
        /// </summary>
        private void CopyInfoToClipboard()
        {
            try
            {
                string data =
                    "Product Name: " + info.Title + "\r\n" +
                    "Product Version: " + info.Version.ToString() + " ," +
                    Properties.Settings.Default.releaseDate.ToString("D");

                Clipboard.SetText(data);

                MessageBox.Show(Resources.InfoCopied, info.Title, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        #endregion
    }
}
